package club.justwill.single.assembler;

import club.justwill.single.bean.ModelResp;
import club.justwill.single.bean.OrderItemResp;
import club.justwill.single.bean.OrdersResp;
import club.justwill.single.bean.ProjectsResp;
import club.justwill.single.persistence.dao.OrderDao;
import club.justwill.single.persistence.dao.OrderItemDao;
import club.justwill.single.persistence.dao.SkuDao;
import club.justwill.single.persistence.jpo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by luoyu on 1/5/16.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class ModelAssemble {
    @Autowired
    ProjectAssemble projectAssemble;
    public List<ModelResp> assembleModels(List<Model> modelList) {
        List<ModelResp> modelRespList = new ArrayList<ModelResp>();

        for (Model model:modelList) {
            modelRespList.add(assembleModel(model));
        }
        return modelRespList;
    }

    public ModelResp assembleModel(Model model) {
        ModelResp modelResp = new ModelResp();
        modelResp.setModelId(model.getModelId()+"");
        modelResp.setModelType(model.getModelType()+"");
        modelResp.setModelUrl(model.getModelUrl());
        List<ProjectsResp> projectsRespList = new ArrayList<ProjectsResp>();
        for (Projects project : model.getProjectsSet()) {
            ProjectsResp projectsResp = projectAssemble.assembleProjectMini(project);
            projectsRespList.add(projectsResp);
        }
        modelResp.setProjectsRespList(projectsRespList);
        return modelResp;
    }
}
